<!-- home -->
<template>
  <div>
    <van-nav-bar :title="title" left-arrow :fixed="true" :placeholder="true" @click-left="$router.go(-1)" />
    <div class="topic-box">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" v-if="list.length>0">
        <div class="item-box" v-for="item in list" :key="item.id" @click="goDetails(item.id)">
          <!-- <div class="img-box">
            <img
              src="https://img2.baidu.com/it/u=2831581151,2017409846&fm=253&fmt=auto&app=138&f=JPEG?w=667&h=500"
              class="img"
            />
          </div> -->
          <div class="info-box">
            <div class="title">{{item.name}}</div>
            <div class="desc">发布时间：{{item.createdAt}}</div>
          </div>
        </div>
      </van-list>
      <van-empty v-else description="暂无数据" />
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" v-if="type == 3">
        <div class="item-video-box">
          <div class="img-box">
            <img
              src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsports%2Ftransform%2F450%2Fw800h450%2F20200531%2Fd6e2-iufmpmp6096738.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1646992588&t=64e251253e939a21c2d64d31da13defe"
            />
            <van-tag color="#3ccb4b">免费</van-tag>
          </div>
          <div class="info-box">
            <div class="title">学习保护自我学习保护自我学习保护自我</div>
            <div class="info">21节 | 超新学习提供</div>
            <div class="edit-box">
              <van-icon name="like">23</van-icon>
              <van-icon name="star">34</van-icon>
            </div>
          </div>
        </div>
        <div class="item-video-box" @click="handlePay">
          <div class="img-box">
            <img
              src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsports%2Ftransform%2F450%2Fw800h450%2F20200531%2Fd6e2-iufmpmp6096738.jpg&refer=http%3A%2F%2Fn.sinaimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1646992588&t=64e251253e939a21c2d64d31da13defe"
            />
            <van-tag color="#ff3535">付费</van-tag>
          </div>
          <div class="info-box">
            <div class="title">学习保护自我</div>
            <div class="info">21节 | 超新学习提供</div>
            <div class="edit-box">
              <van-icon name="like">233</van-icon>
              <van-icon name="star">134</van-icon>
            </div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import { articleList } from '@/api/home.js'
export default {
  data() {
    return {
      loading: false,
      finished: true,
      title: '',
      type: 0,
      list:[],
    }
  },

  computed: {},
  created() {
    if (this.$route.query.type) {
      this.type = this.$route.query.type
      if (this.type == 18) {
        this.title = '男孩子'
      } else if (this.type == 19) {
        this.title = '女孩子'
      } else if (this.type == 20) {
        this.title = '亲子互动'
      } else if (this.type == 3) {
        this.title = '推荐课程'
      }
      this.fetchList(this.type)
    }
  },
  mounted() {},

  methods: {
    async fetchList(id) {
      await articleList({categoryId:id}).then((res) => {
        if(res.code == 200){
          this.list = res.data
        }else{
          this.$notify(res.message)
        }
      })
    },
    goDetails(id){
      this.$router.push({
        path:'/richPage?id='+id
      })
    },
    handlePay(){
      this.$dialog.confirm({
        message: '确认支付 ￥38.8 购买课程吗？',
      })
        .then(() => {
          // on confirm
          this.$toast.success('支付成功~');
          setTimeout(()=>{
            this.$toast.clear()
            this.$router.push({
              path:'/videoDetails'
            })
          },1500)
        })
        .catch(() => {
          // on cancel
        });
    }
  }
}
</script>
<style lang="scss" scoped>
.topic-box {
  width: 100%;
  box-sizing: border-box;
  .item-video-box{
    background: #fff;
    border-radius: .2778rem;
    display: flex;
    align-items: center;
    padding:.2778rem;
    box-sizing: border-box;
    width: 94%;
    margin:.2778rem auto 0;
    .img-box{
      flex: 0 0 3rem;
      position: relative;
      img{
        width:100%;
        height: 2.2rem;
        border-radius: .1389rem;
      }
      .van-tag{
        position: absolute;
        top: .1389rem;
        left: .1389rem;
      }
    }
    .info-box{
      flex:1;
      padding: .1389rem .1389rem .1389rem .2778rem;
      box-sizing: border-box;
      height: 2.2rem;
      position: relative;
      .title{
        width:5.5rem;
        font-size: .4167rem;
        color: #000;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .info{
        font-size: .3333rem;
        color: #999;
        margin-top: .2rem;
      }
      .edit-box{
        position: absolute;
        left: .2778rem;
        bottom: .0556rem;
        font-size: .3333rem;
        width: 100%;
        .van-icon{
          min-width: 1.7rem;
          color: #666;
          display: inline-block;
          &::before{
            margin-right: .1389rem;
            font-size: .3333rem;
            font-weight: bold;
            color: #ff9235;
          }
        }
      }
    }
  }
  .item-box {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0.2778rem 0.4167rem;
    border-bottom: 0.0139rem solid #efefef;
    background: #fff;
    &:last-child {
      border: none;
    }
    .img-box {
      flex: 0 0 1rem;
    }
    .img {
      width: 1.5rem;
      height: 1.5rem;
      border-radius: 0.2rem;
    }
    .info-box {
      padding: 0 0 0 0.2778rem;
      box-sizing: border-box;
      width: calc(100% - 1.4rem);
      .title {
        font-size: 0.4167rem;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        margin-bottom: 0.2rem;
        width: 100%;
      }
      .desc {
        font-size: 0.34rem;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        color: #999;
        width: 100%;
      }
    }
  }
}
</style>
